<?php

App::uses('AdminAppController', 'Admin.Controller');
App::uses('AppController', 'Controller');

class ContactsController extends AdminAppController {

    var $helpers = array('Form');

    function index() {
        $this->paginate = array(
            'limit' => 25,
            'order' => array('Contact.id' => 'desc')
        );

        // we are using the 'Admin' model
        $rows = $this->paginate('Contact');

        // pass the value to our view.ctp
        $this->set('rows', $rows);
    }

    function view($id = null) {
        if (!$id) {
            throw new NotFoundException(__('Invalid post'));
        }
        $post = $this->Contact->findById($id);
        if (!$post) {
            throw new NotFoundException(__('Invalid post'));
        }
        $this->Contact->id = $id;
        $this->Contact->save(array('status' => 1));
        $this->request->data = $post;
    }

    function delete($id = null) {
        if (!$id) {
            throw new NotFoundException(__('Invalid post'));
        }
        if ($this->request->is('get')) {
            throw new MethodNotAllowedException();
        }

        if ($this->Contact->delete($id)) {
            $this->Session->setFlash('Delete success!', 'default', array(), 'good');
        } else {
            $this->Session->setFlash('Delete unsuccess!', 'default', array(), 'bad');
        }
        $this->Redirect(array('action' => 'index'));
    }

}
